package com.sad.dao.impl;

import java.io.IOException;
import java.util.Map;

import org.apache.http.client.methods.RequestBuilder;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

import com.sad.dao.BaseRecord;
import com.sad.model.JsonObject;
import com.sad.model.Orderback;
import com.sad.util.G;

public class OrderbackRecord extends BaseRecord<Orderback> {

	@Override
	protected String getUrl(Map<String, Object> parms) {
		String page = (String) parms.get(G.K.page);
		String pageSize = (String) parms.get(G.K.perPage);
		String condation = (String) parms.get("condation");

		String url = G.system.url + "/toy/order/orderlist?status=d&pageNo=" + page + "&pageSize="
				+ pageSize;

		if (condation != null && !"".equals(condation)) {
			url += "&userid=" + condation;
		}

		return url;
	}

	@Override
	protected JsonObject<Orderback> parserJsonObject(String json) throws JsonParseException,
			JsonMappingException, IOException {
		ObjectMapper mapper = new ObjectMapper();
		return mapper.readValue(json, new TypeReference<JsonObject<Orderback>>() {
		});
	}

	@Override
	protected String postUrl(Map<String, Object> parms) {
		return G.system.url + "/toy/orderback/create";
	}

	@Override
	protected RequestBuilder builderParameter(RequestBuilder builder, Map<String, Object> parms) {
		String orderid = (String) parms.get("orderid");
		String rexcode = (String) parms.get("rexcode");
		String lostdesc = (String) parms.get("lostdesc");

		builder.addParameter("orderid", orderid);
		builder.addParameter("rexcode", rexcode);
		builder.addParameter("lostdesc", lostdesc);

		return builder;
	}
}
